package com.chen.nongansampling.activity;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Point;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import com.chen.nongansampling.R;
import com.chen.nongansampling.adapter.ListViewItemAdapter;
import com.chen.nongansampling.adapter.ListviewEditTextAdapter;
import com.chen.nongansampling.adapter.ListviewTextAdapter;
import com.chen.nongansampling.adapter.PictureAddGridAdapter;
import com.chen.nongansampling.adapter.UpdateOperatorPresenter;
import com.chen.nongansampling.app.BaseApplication;
import com.chen.nongansampling.bean.Callback;
import com.chen.nongansampling.bean.UpdateOperatingRequest;
import com.chen.nongansampling.bean.UpdateOperatorBean;
import com.chen.nongansampling.bean.getOperatingByPkId;
import com.chen.nongansampling.bean.getOperingByPkIdRequest;
import com.chen.nongansampling.bean.sample.TypeList;
import com.chen.nongansampling.bean.tanchubean;
import com.chen.nongansampling.bean.ui.ListviewBean;
import com.chen.nongansampling.custom.CustomScrollGridView;
import com.chen.nongansampling.fragment.BusinessArchivesActivity;
import com.chen.nongansampling.model.CallbackData;
import com.chen.nongansampling.model.Market;
import com.chen.nongansampling.presenterView.UpdateOperatorView;
import com.chen.nongansampling.utils.CommandPhotoUtil;
import com.chen.nongansampling.utils.ImageUtil;
import com.chen.nongansampling.utils.PhotoBitmapUtil;
import com.chen.nongansampling.utils.PhotoSystemOrShoot;
import com.chen.nongansampling.utils.QRCodeUtil;

import java.util.ArrayList;
import java.util.List;

import static com.chen.nongansampling.fragment.getOperatingByPkIdFragment.pkid;
import static com.chen.nongansampling.fragment.ui.businessarchives.BusinessArchivesFragment.marketList;
import static com.chen.nongansampling.fragment.ui.businessarchives.BusinessArchivesFragment.typeList;

public class OperatorDetailActivity extends AppCompatActivity implements UpdateOperatorView {
    private ListView listViewxiangxi;
    private ListView listViewxiala;
    private ListView listViewxiangxi2;
    private com.chen.nongansampling.bean.getOperingByPkIdRequest getOperingByPkIdRequest  = new getOperingByPkIdRequest();
    UpdateOperatorBean operatingBean=new UpdateOperatorBean();;
    ListviewEditTextAdapter listviewEditTextAdapter;
    ListviewEditTextAdapter listviewEditTextAdapter1;
    UpdateOperatorPresenter updateOperatorPresenter = new UpdateOperatorPresenter(OperatorDetailActivity.this);
    public TextView kaitou;
    public List<ListviewBean> list;
    public static List<getOperatingByPkId> lista;
    private   getOperatingByPkId ger;
    private List<String> choose = new ArrayList<>();
    private List<String> chooseShow = new ArrayList<>();
    private List<String> nameid = new ArrayList<>();
    private List<String> nameid2 = new ArrayList<>();
    private List<String> nameidshou = new ArrayList<>();
    private CallbackData<List<TypeList>> typelists;
    public static Bitmap qrcode_bitmap;
    public boolean biaoshi = false;
    /**
     * 存放图片的容器
     */
    private CustomScrollGridView mGridView;

    /**
     * GridView适配器
     */
    private PictureAddGridAdapter gridAdapter;

    /**
     * 管理图片操作
     */
    private CommandPhotoUtil commandPhoto;

    /**
     * 选择图片来源
     */
    private PhotoSystemOrShoot selectPhoto;
    private boolean [] duoxuanbool;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_operator_detail);
        initToolbar();

        kaitou=findViewById(R.id.sample_tool_bar_name);
        listViewxiangxi=(ListView)findViewById(R.id.setting_listview);
        listViewxiala=(ListView)findViewById(R.id.setting_xiala);
        listViewxiangxi2=(ListView)findViewById(R.id.setting_listviewxianshi);

        FrameLayout layout = (FrameLayout)findViewById(R.id.setting_top_background);
        ListView liebiao = (ListView)findViewById(R.id.setting_listview);
        // Intent intent = getIntent();
        // String pkid=intent.getStringExtra("str");
        //System.out.println("传到新页面"+pkid);
        ger = new getOperatingByPkId();
        System.out.println("1111111111111111111111"+lista);
        for(getOperatingByPkId g :lista){
            ger=g;
        }
        String a []  = ger.getName2().split(",");
        for (int i=0;i<a.length;i++){
            nameid.add(a[i]);
            nameid2.add(a[i]);
        }
        generateQrcodeAndDisplay(ger.getQRCode());
        //System.out.println("1111111111111111111111"+ger.getName1());
        ListviewBean<String> list1 = new ListviewBean();
        list1.setData(ger.getOperatingHouseholds());
        list1.setImageSrc(R.mipmap.username);
        list1.setName("姓名");
        list1.setRedStar(true);

        ListviewBean<String> list2 = new ListviewBean();
        list2.setData(ger.getBoothNumber());
        list2.setImageSrc(R.mipmap.tanweihao);
        list2.setName("摊位号");
        list2.setRedStar(true);

        ListviewBean<String> list3 = new ListviewBean();
        list3.setData(ger.getName());
        list3.setImageSrc(R.mipmap.shichangname);
        list3.setName("市场名称");
        list3.setRedStar(true);

        ListviewBean<String> list4 = new ListviewBean();
        list4.setData(ger.getPhone());
        list4.setImageSrc(R.mipmap.phone);
        list4.setName("联系电话");

        ListviewBean<String> list5 = new ListviewBean();
        list5.setData(ger.getName1());
        list5.setImageSrc(R.mipmap.jingyingtype);
        list5.setName("经营种类");
        list5.setRedStar(true);

        ListviewBean<String> list6 = new ListviewBean();
        list6.setData(ger.getBusiness_license());
        list6.setImageSrc(R.mipmap.listview_operator_social_number);
        list6.setName("统一社会信用代码");

        List<ListviewBean> list = new ArrayList<>();
        list.add(list1);
        list.add(list2);
        list.add(list4);

        List<ListviewBean> listE = new ArrayList<>();
        listE.add(list3);
        listE.add(list5);

        List<ListviewBean> listXinyong = new ArrayList<>();
        listXinyong.add(list6);

        listviewEditTextAdapter=new ListviewEditTextAdapter(list, getApplicationContext());
        listViewxiangxi.setAdapter(listviewEditTextAdapter);
        listViewxiala.setAdapter(new ListviewTextAdapter(listE,getApplicationContext(),false));
        listviewEditTextAdapter1=new ListviewEditTextAdapter(listXinyong, getApplicationContext());
        listViewxiangxi2.setAdapter(listviewEditTextAdapter1);
        listViewxiala.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                switch (position)
                {
                    case 0:{
                        if (marketList.size()!=0) {
                            LayoutInflater inflater = LayoutInflater.from(OperatorDetailActivity.this);
                            View layout = inflater.inflate(R.layout.edit_select, null);
                            final EditText edit = (EditText)layout.findViewById(R.id.listview_edit_data);
                            final TextView title = (TextView)layout.findViewById(R.id.listview_title_name);
                            edit.setHint("请输入菜市场名称");
                            title.setText("请选择市场");
                            String s[]=new String[marketList.size()];
                            ArrayList<String> strlist = new ArrayList<String>();
                            ArrayList<Market> marketLists = new ArrayList<Market>();

                            List<tanchubean> list=new ArrayList<>();

                            for (int i=0;i<marketList.size();i++)
                            {
                                if(marketList.get(i).getName().indexOf(edit.getText().toString()) != -1){
                                    strlist.add(marketList.get(i).getName());
                                    marketLists.add(marketList.get(i));
                                    tanchubean<String> list1=new tanchubean();
                                    list1.setName(marketList.get(i).getName());
                                    list.add(list1);
                                }


                            }

                            ListViewItemAdapter adapter = new ListViewItemAdapter(OperatorDetailActivity.this,list);
                            AlertDialog dialogs = new AlertDialog.Builder(OperatorDetailActivity.this)
                                    .setCustomTitle(layout)
                                    //.setView(list)
                                    .setPositiveButton("搜索市场",null)
                                    .setAdapter(adapter, new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialog, int which) {
                                            dialog.dismiss();

                                            TextView t = view.findViewById(R.id.listview_text_data);
                                            t.setText(marketLists.get(which).getName());
                                            t.setTextColor(Color.BLACK);
                                            operatingBean.setUpdatemarketId(marketList.get(which).getPkId());

                                        }
                                    }).create();
                            dialogs.show();
                            // 通过Activity类中的getWindowManager()方法获取窗口管理，再调用getDefaultDisplay()方法获取获取Display对象
                            Display display = OperatorDetailActivity.this.getWindowManager().getDefaultDisplay();
                            // 方法一(推荐使用)使用Point来保存屏幕宽、高两个数据
                            Point outSize = new Point();
                            // 通过Display对象获取屏幕宽、高数据并保存到Point对象中
                            display.getSize(outSize);
                            // 从Point对象中获取宽、高
                            int x = (new Double(outSize.x*0.9)).intValue();
                            int y = (new Double(outSize.y*0.9)).intValue();

                            dialogs.getWindow().setLayout(x,y);
                            //弹出对话框时需要点击输入框才能弹出软键盘
                            dialogs.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
                            dialogs.getButton(AlertDialog.BUTTON_POSITIVE).setTextSize(13);
                            Drawable dr = OperatorDetailActivity.this.getResources().getDrawable(R.drawable.login_btn_selector); //取得图片资源
                            dialogs.getButton(AlertDialog.BUTTON_POSITIVE).setBackground(dr);
                            LinearLayout.LayoutParams PositiveButton =
                                    (LinearLayout.LayoutParams)  dialogs.getButton(DialogInterface.BUTTON_POSITIVE).getLayoutParams();
                            PositiveButton.height = (new Double(outSize.x*0.12)).intValue();
                            PositiveButton.width = (new Double(outSize.x*0.3)).intValue();
                            //设置文字居中
                            PositiveButton.gravity = Gravity.CENTER;
                            PositiveButton.setMargins(new Double(outSize.x-outSize.x*0.3).intValue()/2,
                                    20, new Double(outSize.x-outSize.x*0.3).intValue()/2, 20);
                            dialogs.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {

                                @Override
                                public void onClick(View v) {
                                    if (!TextUtils.isEmpty(edit.getText().toString())) {
                                        ArrayList<String> strlist = new ArrayList<String>();
                                        ArrayList<Market> marketLists = new ArrayList<Market>();
                                        List<tanchubean> list=new ArrayList<>();
                                        for (int i = 0; i < marketList.size(); i++) {
                                            if(marketList.get(i).getName().indexOf(edit.getText().toString()) != -1){
                                                strlist.add(marketList.get(i).getName());
                                                marketLists.add(marketList.get(i));
                                                tanchubean<String> list1=new tanchubean();
                                                list1.setName(marketList.get(i).getName());
                                                list.add(list1);
                                            }
                                        }
                                        String s[] = (String[]) strlist.toArray(new String[strlist.size()]);
                                        ListViewItemAdapter adapter = new ListViewItemAdapter(OperatorDetailActivity.this,list);

                                        AlertDialog.Builder dialog = new AlertDialog.Builder(OperatorDetailActivity.this)
                                                .setAdapter(adapter, new DialogInterface.OnClickListener() {
                                                    @Override
                                                    public void onClick(DialogInterface dialog, int which) {
                                                        dialog.dismiss();
                                                        dialogs.dismiss();
                                                        TextView t = view.findViewById(R.id.listview_text_data);
                                                        t.setText(marketLists.get(which).getName());
                                                        t.setTextColor(Color.BLACK);
                                                        operatingBean.setUpdatemarketId(marketLists.get(which).getPkId());



                                                    }
                                                });
                                        dialog.create().show();

                                    }

                                }
                            });
                        }
                    }break;
                    case 1:{
                        if (typeList!=null) {

                            String s[] = new String[typeList.size()];
                            for (int i = 0; i < typeList.size(); i++) {
                                s[i] = typeList.get(i).getTypeName();
                            }

                            if(!biaoshi){
                                duoxuanbool=new boolean[typeList.size()];
                                String xianshizhonglei[] =ger.getName1().split(",");
                                for(int i = 0; i < xianshizhonglei.length; i++){
                                    for (int j = 0; j < typeList.size(); j++) {
                                        if(xianshizhonglei[i].equals(typeList.get(j).getTypeName())){
                                            duoxuanbool[j] = true;
                                            choose.add(typeList.get(j).getTypeName());

                                            break;
                                        }
                                    }
                                }
                                biaoshi=true;
                            }

                            AlertDialog builder = new AlertDialog.Builder(OperatorDetailActivity.this)
                                    .setTitle("请选择经营种类")
                                    .setIcon(R.mipmap.xuanze)
                                    .setMultiChoiceItems(s, duoxuanbool, new DialogInterface.OnMultiChoiceClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                                            if (isChecked) {

                                                // TextView t = view.findViewById(R.id.listview_text_data);
                                                //t.setTextColor(Color.BLACK);
                                                choose.add(typeList.get(which).getTypeName());

                                                //t.setText(typeList.get(which).getName());
                                                if (typeList.get(which).getTypeId() != null) {
                                                    // System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"+marketList.get(which).getName());
                                                    // System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"+marketList.get(which).getPkId());
                                                    //operatingBean.setTypePkId(typeList.get(which).getPkId());
                                                    nameid.add(typeList.get(which).getTypeId());
                                                    duoxuanbool[which] = true;
                                                }
                                            } else {
                                                choose.remove(typeList.get(which).getTypeName());
                                                nameid.remove(typeList.get(which).getTypeId());
                                                duoxuanbool[which] = false;
                                            }

                                        }
                                    })
                                    .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialog, int which) {
                                            if (choose.size() != 0) {
                                                chooseShow.clear();
                                                for (String name : choose) {
                                                    chooseShow.add(name);
                                                }
                                            }
                                            if (nameid.size() != 0) {
                                                nameid2.clear();
                                                for (String name : nameid) {
                                                    nameid2.add(name);
                                                }
                                            }
                                            TextView t = view.findViewById(R.id.listview_text_data);
                                            t.setTextColor(Color.BLACK);
                                            String names = null;
                                            int i = 0;
                                            for (String name : chooseShow) {
                                                if (i == 0) {
                                                    if (chooseShow.size() == 1) {
                                                        names = name;
                                                    } else {
                                                        names = name + ",";
                                                    }
                                                } else if (i != chooseShow.size() - 1) {
                                                    names = names + name + ",";
                                                } else {
                                                    names = names + name;
                                                }
                                                i++;
                                            }
                                            t.setText(names);
                                        }
                                    })
                                    .create();
                            builder.show();
                            builder.getButton(AlertDialog.BUTTON_POSITIVE).setTextSize(13);
                            // 通过Activity类中的getWindowManager()方法获取窗口管理，再调用getDefaultDisplay()方法获取获取Display对象
                            Display display = OperatorDetailActivity.this.getWindowManager().getDefaultDisplay();
                            // 方法一(推荐使用)使用Point来保存屏幕宽、高两个数据
                            Point outSize = new Point();
                            // 通过Display对象获取屏幕宽、高数据并保存到Point对象中
                            display.getSize(outSize);
                            int x = (new Double(outSize.x*0.9)).intValue();
                            int y = (new Double(outSize.y*0.9)).intValue();

                            Drawable dr = OperatorDetailActivity.this.getResources().getDrawable(R.drawable.login_btn_selector); //取得图片资源
                            builder.getButton(AlertDialog.BUTTON_POSITIVE).setBackground(dr);
                            LinearLayout.LayoutParams PositiveButton =
                                    (LinearLayout.LayoutParams) builder.getButton(DialogInterface.BUTTON_POSITIVE).getLayoutParams();
                            PositiveButton.height = (new Double(outSize.x*0.12)).intValue();
                            PositiveButton.width = (new Double(outSize.x*0.4)).intValue();
                            //设置文字居中
                            PositiveButton.gravity = Gravity.CENTER;
                            PositiveButton.setMargins((x-(new Double(outSize.x*0.4)).intValue())/2,
                                    20, (x-(new Double(outSize.x*0.4)).intValue())/2, 20);
                        }
                    }break;
                }
            }
        });

        initUI();
        addPlus();
    }




    public void show(List<getOperatingByPkId> getlist){
        lista=getlist;
        // System.out.println("111111111111111111111111111111111111"+lista);
        // listViewxiangxi.setAdapter(new ListviewTextAdapter(list, OperatorDetailActivity.this,true));
    }
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        System.out.println(selectPhoto);
        super.onActivityResult(requestCode, resultCode, data);
        if (selectPhoto != null) {

            String photoPath = selectPhoto.getPhotoResultPath(requestCode, resultCode, data);
            if (!TextUtils.isEmpty(photoPath)) {
                commandPhoto.showGridPhoto(photoPath);
            }
        }
    }

    public void initToolbar(){
        Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayShowTitleEnabled(false);//隐藏标题
        toolbar.setNavigationIcon(R.mipmap.back_white);       //加载图标
        toolbar.setTitle("");//经营户信息
        TextView title = findViewById(R.id.sample_tool_bar_name);
        title.setText("经营户编辑 ");
        toolbar.setTitleMarginStart(300);
        toolbar.setTitleTextColor(Color.WHITE);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {   //为图标设置监听器
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }


    public void Onclick(View view){
        UpdateOperatingRequest insertOperatingRequest =new UpdateOperatingRequest();
        insertOperatingRequest.setAccountPkId(BaseApplication.getAccount().getPkId());
        if(!TextUtils.isEmpty(listviewEditTextAdapter.list.get(0).getData().toString())&&!"请选择".equals(listviewEditTextAdapter.list.get(0).getData().toString())){
            if(!TextUtils.isEmpty(listviewEditTextAdapter.list.get(1).getData().toString())&&!"请选择".equals(listviewEditTextAdapter.list.get(1).getData().toString())){
                operatingBean.setUpdatepkId(pkid);
                System.out.println("经营户pkid"+pkid);
                //添加market的pkid
                if( TextUtils.isEmpty(operatingBean.getUpdatemarketId())){
                    for(int i = 0;i<marketList.size();i++){
                        if(marketList.get(i).getName().equals(ger.getName())){
                            operatingBean.setUpdatemarketId(marketList.get(i).getPkId());
                            break;
                        }
                    }
                }
                //添加typr的pkid
                if( TextUtils.isEmpty(operatingBean.getUpdatetypePkId())){
                    for(int i = 0;i<typeList.size();i++){
                        if(typeList.get(i).getTypeName().equals(ger.getName1())){
                            //Toast.makeText(OperatorDetailActivity.this,list.getName(),Toast.LENGTH_LONG).show();
                            operatingBean.setUpdatetypePkId(typeList.get(i).getTypeId());
                            break;
                        }
                    }
                }
                if(listviewEditTextAdapter1.list.get(0).getData()!=null){
                    operatingBean.setBusinesslicense(listviewEditTextAdapter1.list.get(0).getData().toString());
                }

                operatingBean.setUpdateoperatingHouseholds(listviewEditTextAdapter.list.get(0).getData().toString());
                operatingBean.setUpdateboothNumber(listviewEditTextAdapter.list.get(1).getData().toString());
                if(listviewEditTextAdapter.list.get(2).getData()!=null){
                    operatingBean.setUpdatephone(listviewEditTextAdapter.list.get(2).getData().toString());
                }else{
                    operatingBean.setUpdatephone("");
                }
                if(gridAdapter.getImageSize()!=0){
                    Bitmap b = PhotoBitmapUtil.getCompressPhoto((String) gridAdapter.getItem(0));
                    operatingBean.setUpdatephoto(ImageUtil.toBase64String(b));
                    System.out.println("图片的base"+ImageUtil.toBase64String(b));
                }else{
                    if(ger.getPhoto()!=null){
                        operatingBean.setUpdatephoto(ger.getPhoto());
                    }
                }
                insertOperatingRequest.setOperatingbianji(operatingBean);
                insertOperatingRequest.setTypeList(nameid2);
                updateOperatorPresenter.UpdateOperatorPresenterResponseInfo(insertOperatingRequest);

            }else{
                Toast.makeText(OperatorDetailActivity.this,"摊位号不能为空!!!!",Toast.LENGTH_LONG).show();
            }
        }else{
            Toast.makeText(OperatorDetailActivity.this,"姓名不能为空!!!!",Toast.LENGTH_LONG).show();
        }
    }

    public void show(ArrayList<getOperatingByPkId> getlist){
        lista=getlist;
    }


    @Override
    public void UpdateOperator(Callback callback) {

        if (callback.getState()==1)
        {
            Toast.makeText(OperatorDetailActivity.this,"编辑成功",Toast.LENGTH_LONG).show();
            //跳转activity
            Intent intent = new Intent(OperatorDetailActivity.this, BusinessArchivesActivity.class);
            startActivity(intent);
            //          getFragmentManager().on();//suport.v4包
        }else if(callback.getState()==200){
            Toast.makeText(OperatorDetailActivity.this,callback.getAlertMessage(),Toast.LENGTH_LONG).show();
        }
    }

    @Override
    public void onError(String result) {
        //Toast.makeText(OperatorDetailActivity.this,result,Toast.LENGTH_LONG).show();
    }

    @Override
    public void onResume() {
        super.onResume();
        updateOperatorPresenter.BindPresentView(this);
        updateOperatorPresenter.onCreate();
    }
    private void initUI() {
        mGridView = (CustomScrollGridView) OperatorDetailActivity.this.findViewById(R.id.gv_all_photos);
    }
    private void addPlus() {
        gridAdapter = new PictureAddGridAdapter(OperatorDetailActivity.this, 1,ger.getPhoto());
        mGridView.setAdapter(gridAdapter);
        //   getActivity().getSupportFragmentManager().saveFragmentInstanceState(SampleFragment.newInstance());
        // 选择图片获取途径
        selectPhoto = new PhotoSystemOrShoot(OperatorDetailActivity.this) {
            @Override
            public void onStartActivityForResult(Intent intent, int requestCode) {
                if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.N){
                    intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
//                    Uri contentUri = FileProvider.getUriForFile(context,"com.skyrin.bingo.fileprovider",apkFile);
//                    intent.setDataAndType(contentUri,"application/vnd.android.package-archive");
                    startActivityForResult(intent, requestCode);
                }else {
                    //        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//                    intent.setDataAndType(
//                            Uri.fromFile(apkFile),
//                            "application/vnd.android.package-archive");
                    startActivityForResult(intent, requestCode);
                }
            }
        };
        commandPhoto = new CommandPhotoUtil(OperatorDetailActivity.this, mGridView, gridAdapter, selectPhoto);
    }

    private void generateQrcodeAndDisplay(String url) {
//        content = et_content.getText().toString();
//        String str_width = et_width.getText().toString();
//        String str_height = et_height.getText().toString();
//        if (str_width.length() <= 0 || str_height.length() <= 0) {
//            width = 650;
//            height = 650;
//        } else {
//            width = Integer.parseInt(str_width);
//            height = Integer.parseInt(str_height);
//        }
//
//        if (content.length() <= 0) {
//            Toast.makeText(this, "你没有输入二维码内容哟！", Toast.LENGTH_SHORT).show();
//            return;
//        }
//        QRCodeUtil  qrcode_bitmap = QRCodeUtil.createQRCodeBitmap("www.baidu.com" , 500, 500, "UTF-8",
//                "H"  , "1", Color.BLACK, Color.WHITE);
        float a = 0;
        ImageView qrCode = findViewById(R.id.setting_top_object);
        qrcode_bitmap = QRCodeUtil.createQRCodeBitmap(url, 1000, 1000, "UTF-8", "H", "1", Color.BLACK, Color.WHITE, null, a, null);

        qrCode.setImageBitmap(qrcode_bitmap);

    }
}
